home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk8 / ptrdata / ptrdata.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  2KB  |  87 lines

  1.  
  2. /* ptrdata version 1.00, Donald L. Wahl  2/13/88                        */
  3. /* generate C data for SetPointer() from devs:system-configuration file */
  4. #include "intuition/intuition.h"
  5. #include "intuition/intuitionbase.h"
  6. #include "stdio.h"
  7.  
  8. FILE *source, *destination; /* files */
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13.   {
  14.     struct Preferences prefs;
  15.     char buffer[64];
  16.     int c,calc,height,width;
  17.     long size;
  18.     if(argc != 3)
  19.       {
  20.         printf("Usage:\nptrdata devs:system-configuration datafile\n");
  21.         exit(0);
  22.       } 
  23.  
  24.     if((source = fopen(argv[1], "r"))== NULL)
  25.       {
  26.         printf("Can't open %s\n",argv[1]);
  27.         exit(0);
  28.       } 
  29.     /* check that file is correct size for prefs */ 
  30.     fseek(source,0l,2);
  31.     size = ftell(source);
  32.     if(size != sizeof(struct Preferences))
  33.       {
  34.         printf("File %s is not a preferences file\n",argv[1]);
  35.         fclose(source);
  36.         exit(0);
  37.       }      
  38.     fseek(source,0l,0);
  39.     fread((char *)&prefs,(sizeof(struct Preferences)),1,source);
  40.     fclose(source);
  41.     if((destination = fopen(argv[2], "w"))== NULL)
  42.       {
  43.         printf("Can't open %s\n",argv[2]);
  44.         exit(0);
  45.       } 
  46.     width = height = calc = 0;  
  47.     c = 33;  
  48.     while(c > 0)  /* get height */
  49.       {
  50.         if((prefs.PointerMatrix[c] || prefs.PointerMatrix[c - 1]) && !height)
  51.           {
  52.             height = (c - 1) / 2;
  53.           }  
  54.         calc |= prefs.PointerMatrix[c];
  55.         calc |= prefs.PointerMatrix[c - 1];      
  56.         c -= 2;
  57.       } 
  58.     c = 16; 
  59.     while(c > 0)  /* get width (but it don't care ??) */  
  60.       {
  61.         if(calc & 1)
  62.           {
  63.             break;
  64.           } 
  65.         calc = calc >> 1; 
  66.         c--;
  67.       }  
  68.     width = c; 
  69.     sprintf(buffer,"#define PTR_WIDTH %dl\n",width);  
  70.     fputs(buffer,destination);  
  71.     sprintf(buffer,"#define PTR_HEIGHT %dl\n",height);
  72.     fputs(buffer,destination);  
  73.     sprintf(buffer,"#define PTR_XOFFSET %dl\n",prefs.XOffset);
  74.     fputs(buffer,destination);  
  75.     sprintf(buffer,"#define PTR_YOFFSET %dl\n",prefs.YOffset);
  76.     fputs(buffer,destination);  
  77.     fputs("\n\nUSHORT ptrdata[] = \n{\n",destination);
  78.     for(c = 0;c < POINTERSIZE;c += 2)
  79.       {
  80.         sprintf(buffer,"0x%04.4x, 0x%04.4x,\n",prefs.PointerMatrix[c],prefs.PointerMatrix[c + 1]);
  81.         fputs(buffer,destination);
  82.       } 
  83.     fputs("};\n",destination); 
  84.     fclose(destination);
  85.  
  86.   }
  87.